package com.uenpay.res.widget.dialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.ColorDrawable;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.uenpay.base.R;

/**
 * Created by DELL on 2017/6/18.
 */

public class WhiteBgDialog {
    private int resLayout;
    private Context context;
    private Dialog dialog;
    private Display display;
    private View.OnClickListener listener;
    private Button btnLeft;
    private Button btnRight;

    public WhiteBgDialog(Context context, int resLayout) {
        this.context = context;
        this.resLayout = resLayout;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
        buildDialog();
    }

    private void buildDialog() {

        View view = LayoutInflater.from(context).inflate(resLayout, null);
        dialog = new Dialog(context, R.style.AlertDialogStyle);
        dialog.setContentView(view);
        btnLeft = (Button) (view.findViewById(R.id.btn_left));
        btnRight = (Button) (view.findViewById(R.id.btn_right));

        Window dialogWindow = dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width= context.getResources().getDimensionPixelSize(R.dimen.dp_272);
        lp.height = context.getResources().getDimensionPixelSize(R.dimen.dp_176);
        dialogWindow.setBackgroundDrawable(new ColorDrawable());
        dialogWindow.setAttributes(lp);
        dialog.show();
    }

    public void setOnClickListener(View.OnClickListener listener) {
        this.listener = listener;
        if (listener != null) {
            btnLeft.setOnClickListener(listener);
            btnRight.setOnClickListener(listener);
        }
    }


    public void dissmiss() {
        if (dialog != null) {
            dialog.dismiss();
        }
    }
}
